/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package TableCreate;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author 
 */
public class CreateTable {
    public static void main(String[] args) {
        String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
        String userid = "mhs115314034"; // gantikan dengan username anda
        String password = "mhs115314034"; // gantikan dengan password anda
//                String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
//    String userid = "hr"; // gantikan dengan username anda
//    String password = "hr"; // gantikan dengan password anda

        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(password);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            statement.executeQuery("create table baranggudangt (idbarang varchar2(4) constraint baranggudangt_pk primary key,"
                    + " namabarang varchar2(20) not null unique,"
                    + " jumlahbarang number(6) not null,"
                    + " hargabarang number(6) not null)");
            statement.executeQuery("create table usergudangt (username varchar2(10) constraint usergudangt_pk primary key,"//1
                    + " namauser varchar2(25) not null,"
                    + " alamatuser varchar2(50) not null,"
                    + " notelepon varchar2(15) not null,"
                    + " jenisuser varchar2(8) not null,"
                    + " password varchar2(10) not null)");
            statement.executeQuery("create table pemesananbarang (kodepemesanan varchar2(29) constraint pemesananbarang_pk primary key ,"//2
//                    + " waktupemesanan varchar2(10) not null,"
                    + " jumlahbarang number(26) not null,"
//                    + " namabarang varchar2(20) not null,"
                    + " idbarang varchar2(20) constraint pemesananbarang_fk1 references baranggudangt(idbarang),"
                    + " username varchar2(26) constraint pemesananbarang_fk2 references usergudangt(username))");
            statement.executeQuery("create table penerimaanbarang (kodepenerimaan varchar2(9) constraint penerimaanbarang_pk primary key ,"//2
//                    + " waktupenerimaan varchar2(10) not null,"
                    + " jumlahbarang number(6) not null,"
//                    + " hargabarang number(6) not null,"
//                    + " namabarang varchar2(20) not null,"
                    + " idbarang varchar2(4) constraint penerimaanbarang_fk1 references baranggudangt(idbarang),"
                    + " username varchar2(10) constraint penerimaanbarang_fk2 references usergudangt(username))");
            System.out.println("table created");
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
        }
    }
}
